#include "PettingZoo.h"

Game* Game::Configure()
{
	Root::GetSingleton().SetProperty(Root::PROP_WINDOWTITLE, "PettingZoo");

	Root::GetSingleton().InstallRenderer("RenderMethodDirectDraw");
	Root::GetSingleton().InstallRenderer("RenderMethodOpenGLES");

	return new PettingZoo;
}

Surface* g_Surface = NULL;
float g_PosX[32];
float g_PosY[32];
int g_Index = 0;

void PettingZoo::Init()
{
	g_Surface = Root::GetSingleton().GetRenderer()->CreateSurface(Device::Get().GetWidth(), Device::Get().GetHeight());
}

void PettingZoo::Resize(int a_Width, int a_Height)
{
	//if (g_Surface) { g_Surface->Resize(a_Width, a_Height); }
}

void PettingZoo::Update()
{
	if (TouchScreen::Get().Pressed())
	{
		Log::GetSingleton().Print("Pressed (%.2f, %.2f)", TouchScreen::Get().GetX(), TouchScreen::Get().GetY());

		g_PosX[g_Index] = (float)TouchScreen::Get().GetX();
		g_PosY[g_Index] = (float)TouchScreen::Get().GetY();

		g_Index++;
	}
}

void PettingZoo::Render()
{
	g_Surface->Lock();

		g_Surface->Fill(Color::CGREEN);

		for (int i = 1; i < g_Index; i++)
		{
			g_Surface->Line(
				g_PosX[i - 1] * Device::Get().GetRealWidth(), g_PosY[i - 1] * Device::Get().GetRealHeight(),
				g_PosX[i]     * Device::Get().GetRealWidth(), g_PosY[i]     * Device::Get().GetRealHeight(),
				Color::CRED
			);
		}

	g_Surface->Unlock();

	g_Surface->Draw(0, 0);
}